﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;



using TimKen.DataEntity;
using TimKen.BussLogic;
using TimKen.App;
using System.Data;
using System.Text;



namespace TimKen.Web.Admin.SystemConfig
{
    public partial class SystemConfig_Edit : TimKen.App.AdminPage
    {

        public override string ActionCode
        {
            get
            {
                return "93";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindResources();
                BindData();

            }
         }


        private void BindData()
        {

            if (SystemConfigManager.SystemConfig.CreditCheck)
                this.rblCreditCheck.Items[0].Selected = true;
            else
                this.rblCreditCheck.Items[1].Selected = true;


            this.txtPasswordExpired.Text = SystemConfigManager.SystemConfig.PasswordExpired.ToString();
            this.txtAmountToPointsR.Text = SystemConfigManager.SystemConfig.AmountToPointsR.ToString();
            this.txtAmountToPointsD.Text = SystemConfigManager.SystemConfig.AmountToPointsD.ToString();

            this.cbDisplayPromote.Checked = SystemConfigManager.SystemConfig.IsDisplayPromote;
        }

        protected void BindResources()
        {
            btnConfirm.Text = GetLangString("SaveConfig");
            rblCreditCheck.Items.Add(new ListItem(GetLangString("Yes"), "1"));
            rblCreditCheck.Items.Add(new ListItem(GetLangString("No"), "0"));
        }


      

        protected void btnConfirm_Click(object sender, EventArgs e)
        {
            BussLogic.SystemConfig config = new TimKen.BussLogic.SystemConfig();

            if (this.rblCreditCheck.Items[0].Selected)
                config.CreditCheck = true;
            else
                config.CreditCheck = false;

            config.PasswordExpired = TypeParse.StrToInt(this.txtPasswordExpired.Text.Trim(), 0);

            config.AmountToPointsR = TypeParse.StrToInt(this.txtAmountToPointsR.Text.Trim(),0);
            config.AmountToPointsD = TypeParse.StrToInt(this.txtAmountToPointsD.Text.Trim(),0);
            config.IsDisplayPromote = this.cbDisplayPromote.Checked;

            SystemConfigManager.UpdateSystemConfig(config);
            
            Response.Redirect(Request.RawUrl);
        }

      

    }
}
